package com.fintecher.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2017/2/22.
 */
public class Utils {

    /**
     *
     * @param end
     * @param start
     * @return 票据期限
     */
    public String getTimeDifferenceForMonth(Date end, Date start) {
        SimpleDateFormat dfs = new SimpleDateFormat("yyy-MM-dd");
        long between = (end.getTime() - start.getTime()) / 1000;
        int month = (int) (between / (24 * 3600 * 30));
        String positiveDeadline;
        if (month == 0) {
            positiveDeadline = "一月期";
        } else if (month == 1) {
            positiveDeadline = "二月期";
        } else if (month == 2) {
            positiveDeadline = "三月期";
        } else if (month == 3) {
            positiveDeadline = "四月期";
        } else if (month == 4) {
            positiveDeadline = "五月期";
        } else if (month == 5) {
            positiveDeadline = "六月期";
        } else {
            positiveDeadline = "-----";
        }
        return positiveDeadline;
    }

    /**
     *
     * @param end
     * @return 票据剩余期限
     * @throws ParseException
     */

    public int getTimeDifferenceForDay(Date end) throws ParseException {
        SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd");
        Date now = dfs.parse(dfs.format(new Date()));
        long between = (end.getTime() - now.getTime()) / 1000;
        int days = (int) between / (24 * 3600);
        return days;
    }

    /**
     *
     * @param time
     * @return
     */
    public String transferFormat(Date time){
        SimpleDateFormat dfs=new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");
        String it=dfs.format(time);
        return it;
    }
}
